package com.example.demo;

import java.util.Optional;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
public class KafkaReceiver {
	private Logger logger = LoggerFactory.getLogger(KafkaReceiver.class);
	
	@KafkaListener(topics = {KafkaConfig.TOPICS_SEND_MESSAGE}, groupId = KafkaConfig.GROUP_1)
    public void listen(ConsumerRecord<?, ?> record) {
        Optional<?> kafkaMessage = Optional.ofNullable(record.value());
        if (kafkaMessage.isPresent()) {
            Object message = kafkaMessage.get();
            logger.info("【1】record =" + record);
            logger.info("【1】message =" + message);
            
            logger.info("【1】" + record.key());
        }
    }
}
